#include "stdafx.h"
#include "app_config.h"
#include "str_utils.h"
#include "Winsock.h"

bool GetAppConfig(wchar_t* argv[], size_t argc, OUT AppConfig& appConfig)
{
	appConfig.LocalPath = (argc > 1) ? (argv[1]) : L"..\\testLocal";
	appConfig.RemotePath = (argc > 2) ? (argv[2]) : L"testRemote";
	appConfig.UserName = "demo";
	appConfig.Password = "demo";
	appConfig.ServerDFS = "58.215.187.15:8088";
	appConfig.ServerLog = "58.215.187.15";
	appConfig.UserID = 11;

	char buf[256];

	/* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
    WORD wVersionRequested;
    WSADATA wsaData;
    int err;
	wVersionRequested = MAKEWORD(1, 0);

    err = WSAStartup(wVersionRequested, &wsaData);
    if (err != 0) 
	{
        /* Tell the user that we could not find a usable */
        /* Winsock DLL.                                  */
        printf("WSAStartup failed with error: %d\n", err);
        return 1;
    }

	if (gethostname(buf, sizeof(buf)) == 0)
		appConfig.LocalHostName = buf;

	{
		std::wstring::const_reference it = appConfig.LocalPath.back();
		if (it != '\\' && it != '/')
			appConfig.LocalPath.push_back('\\');
	}

	{
		std::wstring::const_reference it = appConfig.RemotePath.back();
		if (it != '\\' && it != '/')
			appConfig.RemotePath.push_back('\\');
	}

	return true;
}